<?php

//面包屑
$this->breadcrumbs=array(
	'综合控制台'=>array($this->pre_module_url.'/index/index'),
	'产品管理'=>array($this->pre_module_url.'/productSale/admin'),
	'发布宝贝'=>array($this->pre_module_url.'/product/create/step/1'),
);
//编辑产品时
if(!$model->isNewRecord){
	//将产品属性格式化成数据
	if(!empty($model->attribute)){
		$activeAttrbute = array();
		foreach($model->attribute as $val){
			if(isset($activeAttrbute[$val->za_id])){
				if(is_array($activeAttrbute[$val->za_id])){
					$activeAttrbute[$val->za_id][] = $val->zpa_val;
				}else{
					$activeAtt = $activeAttrbute[$val->za_id];
					$activeAttrbute[$val->za_id] = array();
					$activeAttrbute[$val->za_id][] = $activeAtt;
					$activeAttrbute[$val->za_id][] = $val->zpa_val;
				}
			}else{
				$activeAttrbute[$val->za_id]=$val->zpa_val;
			}
		}
	}
	//将产品规格格式化成数据
	if(!empty($model->standard)){
		foreach($model->standard as $val){
			//产品规格
			if(isset($activeStandard[$val->za_id])){
					$activeStandard[$val->za_id] = array_merge((array)$activeStandard[$val->za_id],(array)$val->zpa_val);
			}else{
					$activeStandard[$val->za_id] = (array)$val->zpa_val;
			}
		}
	}
	
	//将产品规格图片格式化成数据
	if(!empty($model->standard)){
		foreach($model->standard as $val){
			if($val->zps_photo=='2'){
				$activeStaColor[$val->za_id][$val->zpa_val] = $val->zpa_pic;
			}
		}
	}
	
	//载入价格体系
	if(!empty($model->price)){
		foreach($model->price as $val){
			$activePrice[$val->zpa_id.'-v'] = $val->zps_price;
		}
	}
	
	//载入规格库存体系
	if(!empty($model->spec)){
		foreach($model->spec as $val){
			//设索引数组，用以查找判断选中的库存体系ID
			$activeSpec[$val->zpa_id] = $val->zpa_val;
			$activeSpec[$val->zpa_id.'-v'] = array(
					'stock'=>$val->zpa_stock,
					'no'=>$val->zpa_pro_no,
			);
		}
	}
	if(F::setting('pointsys')==2){
		//载入积分体系
		if(!empty($model->propoint)){
			foreach($model->propoint as $val){
				//会员等级=》积分
				$activePoint[$val->zmt_id] = $val->zpn_point;
			}
		}
	}
}

//载入分类模型
$category = Category::model()->findByPk($model->zca_id);
//载入颜色
$color = Product::model()->getColor();


?>
<div class="hr_12"></div>

<!--发布宝贝 start-->
<div class="selling_top_tip c_f">
	<?php //if($model->isNewRecord){?>
	<p class="f_r">
		<?php echo CHtml::linkbtn('返回重选类目',(!$model->isNewRecord)?array($this->pre_module_url.'/productCreate/update/id/'.$model->zp_id.'/step/1'):array($this->pre_module_url.'/productCreate/create/step/1'),array('onclick'=>'return confirm("确认重选类目吗，规格属性信息会丢失！")'))?>
		<span class="c_999">返回重选类目会造成已填写的信息丢失，请慎重操作！</span>
	</p>
	<?php //}?>
	<p class="ff_s f_l">
		您选择的类目：
		<?php if($category->zca_topid!=0){?>
		<span><?php echo CHtml::encode(Category::model()->getTitle($category->zca_topid))?>&gt; </span>
		<?php }?>
		<span><?php echo  CHtml::encode(Category::model()->getTitle($category->zca_parentid))?> &gt; </span>
		<span><?php echo  CHtml::encode(Category::model()->getTitle($category->zca_id))?></span>
	</p>
</div>
<!-- 表单开始 -->
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'product-form',
	'enableAjaxValidation'=>false,
)); ?>
<?php echo $form->hiddenField($model,'zca_id')?>
<?php echo $form->hiddenField($model,'zp_id')?>
<div class="selling_proinfo mt10">
		<div class="info_box">
			<div class="hd c_f"><h2 class="fs_14 f_l">1.宝贝基本信息</h2><span class="c_444">（<em class="xing">*</em>表示该项必填）</span></div>
			<ul class="form_list">
				<li class="c_f"><span class="tit"><em class="xing">*</em>宝贝标题：</span>
					<div class="cont f_l">
					<?php echo $form->textField($model,'zp_name',array('size'=>60,'maxlength'=>255,'class'=>'t_ipt ipt_bg w_300','id'=>"product_zp_name")); ?>
					<span id="product_zp_nameTip"></span>
					</div>
				</li>
				<!-- 宝贝属性 -->
				<li class="c_f"><span class="tit">宝贝属性：</span>
					<div class="cont f_l">
						<p class="mb c_999">尽可能完整填写产品属性，增加被买家搜索到的机会</p>
						<div class="pro_attribute">
						<?php  $this->widget('zii.widgets.CListView', array(
								'dataProvider'=>Attribute::model()->loadAttByCateId($category->zca_id),
								'itemView'=>'_view_att',
								'emptyText'=>'',
								'template'=>'{items}',
								'itemsTagName'=>'ul',
								'itemsOptions'=>array('class'=>'form_list'),
								'viewData'=>array('activeAttrbute'=>isset($activeAttrbute)?$activeAttrbute:''),
						)); ?>
						</div>
					</div>
				</li>
				<li class="c_f"><span class="tit"><em class="xing">*</em>一口价：</span>
					<div class="cont f_l">
						<?php echo $form->textField($model,'zp_price',array('id'=>"product_zp_price",'class'=>'t_ipt ipt_bg')); ?>元
						<span id="product_zp_priceTip"></span>
					</div>
				</li>
			</ul>
				<!-- 宝贝规格 -->
				<?php   $this->widget('zii.widgets.CListView', array(
					'dataProvider'=>Attribute::model()->loadStaByCateId($category->zca_id),
					'itemView'=>'_view_sta',
					'emptyText'=>'',
					'template'=>'{items}',
					'tagName'=>'div',
					'itemsTagName'=>'div',
					'itemsOptions'=>array('class'=>'list_table'),
					'htmlOptions'=>array('class'=>''),
					'viewData'=>array('activeStandard'=>isset($activeStandard)?$activeStandard:'',
									  'activeStaColor'=>isset($activeStaColor)?$activeStaColor:''
								),
				)); ?>
				<ul class="form_list">
<?php //--------------------------------------- 价格库存表体系 star -------------------------------------------------------------?>
				<?php  $cateSta = Attribute::model()->getSta($category->zca_id,array(2,3),array(1,2));
						if(count($cateSta)==2){
////////////////////////////////如果有两组规格
							$sta1 = explode(',',$cateSta[0]['za_value']);
							$sta2 = explode(',',$cateSta[1]['za_value']);
				?>
				<li class="c_f"><span class="tit">&nbsp;</span>
					<div class="cont f_l">
						<div id="attSta" class="attribute_tab <?php if(!isset($activeStandard)&&empty($activeStandard)) echo 'd_n';?>">
							<table width="95%" cellpadding="0" cellspacing="0">
								<tr>
									<th width="22%"><?php echo $cateSta[0]['za_title']?></th>
									<th width="20%"><?php echo $cateSta[1]['za_title']?></th>
									<th width="18%">价格</th>
									<th width="18%">数量</th>
									<th width="">商家编码</th>
								</tr>
								<?php if(!empty($sta1)){foreach($sta1 as $key=>$val1){?>
								<?php $selectClass = $cateSta[0]['za_id']."_".$key ?>
								<tr class="<?php //判断修改产品的时候是否显示该行
												if(isset($activeStandard[$cateSta[0]['za_id']])){
													if(in_array($val1,$activeStandard[$cateSta[0]['za_id']])){
														echo 'select ';
													}else{
														echo ' d_n ';
													}
												}else{ echo ' d_n ';}?> <?php echo $selectClass;?>">
									<td class="pl10"><label class="color_lump" <?php if($cateSta[0]['za_photo']=='2'){ echo $color[$val1];} ?> for=""></label><label class="labelname" title="" for=""><?php echo $val1;?></label></td>
									<td colspan="4" class="onpd">
										<table width="100%">
											<?php if(!empty($sta1)){foreach ($sta2 as $key2=>$val2){ ?>
											<?php $selectClass = $cateSta[1]['za_id']."_".$key2 ?>
											<tr class="<?php //判断修改产品的时候是否显示该行
														if(isset($activeStandard[$cateSta[1]['za_id']])){
															if(in_array($val2,$activeStandard[$cateSta[1]['za_id']])){
																echo ' select ';
															}else{
																echo ' d_n ';
															}
														}else{ echo ' d_n ';}?><?php echo $selectClass;?>">
												<?php //取规格索引，用来导渲染规格价格，规格库存，规格商家编号
													if(isset($activeSpec)){
														if($key = array_search($val1.','.$val2,$activeSpec)){
															 $spid = $key.'-v';
														}else{
															$spid = '';
														}
													}else{
														$spid = '';
													}
												?>
												<td width="25.6%" class="b_r"><?php echo $val2;?><input type="hidden" name='attsta[val][]' value="<?php echo $val1.','.$val2;?>")?></td>
												<td width="23%" class="b_r"><input class="t_ipt ipt_bg w_80 v_price" type="text" name="attsta[price][]" value="<?php if(isset($activePrice)){ if(isset($activePrice[$spid])){ echo $activePrice[$spid];}}?>" /></td>
												<td width="23%" class="b_r"><input class="t_ipt ipt_bg w_80 invent v_num" type="text" name="attsta[num][]" value="<?php if(isset($activeSpec)){ if(isset($activeSpec[$spid])){ echo $activeSpec[$spid]['stock'];}}?>" /></td>
												<td width=""><input class="t_ipt ipt_bg w_100" type="text" name="attsta[no][]" value="<?php if(isset($activeSpec)){ if(isset($activeSpec[$spid])){ echo $activeSpec[$spid]['no'];}}?>" /></td>
											</tr>
											<?php }} ?>
										</table>
									</td>
								</tr>
								<?php }} ?>
							</table>
						</div>
					</div>
				</li>
				<?php }elseif(count($cateSta)==1){
//////////////////////////////////如果只有一组规格
							$sta1 = explode(',',$cateSta[0]['za_value']);
							if(!empty($activeStandard)){
								foreach($activeStandard as $key=>$val){};
							}
				?>
				<li class="c_f"><span class="tit">&nbsp;</span>
					<div class="cont f_l">
						<div id="attSta" class="attribute_tab <?php if(empty($model->standard)) echo "d_n"?>">
							<table width="95%" cellpadding="0" cellspacing="0">
								<tr>
									<th width="25.8%"><?php echo $cateSta[0]['za_title']?></th>
									<th width="23%">价格</th>
									<th width="23.2%">数量</th>
									<th width="">商家编码</th>
								</tr>
								<?php if(!empty($sta1)){foreach($sta1 as $key=>$val1){?>
								<?php $selectClass = $cateSta[0]['za_id']."_".$key ?>
								<tr class="<?php echo (!empty($activeStandard)&&in_array($val1,$val))?"select":"d_n"?> <?php echo $selectClass;?>">
									<td colspan="4" class="onpd">
										<table width="100%">
											<tr class="select">
												<?php //取规格索引，用来导渲染规格价格，规格库存，规格商家编号
													if(isset($activeSpec)){
														if($key = array_search($val1,$activeSpec)){
															 $spid = $key.'-v';
														}else{
															$spid = '';
														}
													}else{
														$spid = '';
													}
												?>
												<td width="25.6%" class="b_r"><?php echo $val1;?><input type="hidden" name='attsta[val][]' value="<?php echo $val1?>")?></td>
												<td width="23%" class="b_r"><input class="t_ipt ipt_bg w_80 v_price" type="text" name="attsta[price][]" value="<?php if(isset($activePrice)){ if(isset($activePrice[$spid])){ echo $activePrice[$spid];}}?>" /></td>
												<td width="23%" class="b_r"><input class="t_ipt ipt_bg w_80 invent v_num" type="text" name="attsta[num][]" value="<?php if(isset($activeSpec)){ if(isset($activeSpec[$spid])){ echo $activeSpec[$spid]['stock'];}}?>" /></td>
												<td width="28.2%"><input class="t_ipt ipt_bg w_100" type="text" name="attsta[no][]" value="<?php if(isset($activeSpec)){ if(isset($activeSpec[$spid])){ echo $activeSpec[$spid]['no'];}}?>" /></td>
											</tr>
										</table>
									</td>
								</tr>
								<?php }} ?>
							</table>
						</div>
					</div>
				</li>
				<?php } ?>
<?php //------------------------------------- 价格库存表体系 end --------------------------------------------------------------------?>
				<li class="c_f"><span class="tit"><em class="xing">*</em>宝贝数量：</span>
					<div class="cont f_l">
						<?php echo $form->textField($model,'zp_inventory',array('id'=>'inventory','class'=>'t_ipt ipt_bg')); ?>
						<span id="inventoryTip"></span>
					</div>
				</li>
				<?php if(F::setting('pointsys')==2){ ?>
				<!-- 积分体系 star -->
				<li class="c_f"><span class="tit"><em class="xing">*</em>赠送积分：</span>
					<div class="cont f_l"><div class="attribute_tab">
						<table width="95%" cellpadding="0" cellspacing="0">
								<tr>
									<th width="40%" class="t_c">会员等级</th>
									<th width="60%" class="t_c">赠送积分</th>
								</tr>
								<?php $memtype = MemType::model()->getMemtype(1) //买家会员等级 ?>
								<?php if(!empty($memtype)){ foreach($memtype as $key=>$val){?>
								<tr> 
									<td><?php echo CHtml::encode($val)?></td> 
									<td><?php echo CHtml::textField("ProPoint[$key]",isset($activePoint)?$activePoint[$key]:'',array('class'=>'t_ipt ipt_bg w_160 v_num'))?></td> 
								</tr>
								<?php }}?>
						</table>
						</div>
					</div>
				</li>
				<!-- 积分体系 end -->
				<?php } ?>
				<!-- 产品图片 star -->
				<li class="c_f"><span class="tit"><em class="xing">*</em>宝贝图片：</span>
					<div class="cont f_l">
						<ul class="uploadimg c_f">
							<li class="f_l">
								<img id="img1" src="<?php if(!empty($model->proimg[0])){echo $model->proimg[0]->zpg_url;}else{echo "/images/pro_img.jpg";}?>" alt="" />
								<a class="mem_btn filelink" href="javascript:" onclick="uploadimg('1')">点击上传
									<input type="file" id="uploadimg1" multiple name="image"/>
								</a>
								<?php if(!empty($model->proimg[0])) echo CHtml::link('删除图片','javascript:',array('class'=>'mem_btn filelink del ','onclick'=>"removeimg('1')"))?>
								<input type="hidden" id="proimage1" name="proimage[url][]" value="<?php if(!empty($model->proimg[0])) echo $model->proimg[0]->zpg_url?>" />
								<input type="hidden" id="proimgid1" name="proimage[id][]" value="<?php if(!empty($model->proimg[0])) echo $model->proimg[0]->zta_id?>" />
							</li>
							<li>
								<img id="img2" src="<?php if(!empty($model->proimg[1])){echo $model->proimg[1]->zpg_url;}else{echo "/images/pro_img.jpg";}?>" alt="" />
								<a class="mem_btn filelink" href="javascript:" onclick="uploadimg('2')">点击上传
									<input type="file" id="uploadimg2" multiple name="image"/>
								</a>
								<?php if(!empty($model->proimg[1])) echo CHtml::link('删除图片','javascript:',array('class'=>'mem_btn filelink del ','onclick'=>"removeimg('2')"))?>
								<input type="hidden" id="proimage2" name="proimage[url][]"  value="<?php if(!empty($model->proimg[1])) echo $model->proimg[1]->zpg_url?>"/>
								<input type="hidden" id="proimgid2" name="proimage[id][]"  value="<?php if(!empty($model->proimg[1])) echo $model->proimg[1]->zta_id?>"/>
							</li>
							<li>
								<img id="img3" src="<?php if(!empty($model->proimg[2])){echo $model->proimg[2]->zpg_url;}else{echo "/images/pro_img.jpg";}?>" alt="" />
								<a class="mem_btn filelink" href="javascript:" onclick="uploadimg('3')">点击上传
									<input type="file" id="uploadimg3" multiple name="image"/>
								</a>
								<?php if(!empty($model->proimg[2])) echo CHtml::link('删除图片','javascript:',array('class'=>'mem_btn filelink del ','onclick'=>"removeimg('3')"))?>
								<input type="hidden" id="proimage3" name="proimage[url][]"  value="<?php if(!empty($model->proimg[2])) echo $model->proimg[2]->zpg_url?>"/>
								<input type="hidden" id="proimgid3" name="proimage[id][]"  value="<?php if(!empty($model->proimg[2])) echo $model->proimg[2]->zta_id?>"/>
							</li>
							<li>
								<img id="img4" src="<?php if(!empty($model->proimg[3])){echo $model->proimg[3]->zpg_url;}else{echo "/images/pro_img.jpg";}?>" alt="" />
								<a class="mem_btn filelink" href="javascript:" onclick="uploadimg('4')">点击上传
									<input type="file" id="uploadimg4" multiple name="image"/>
								</a>
								<?php if(!empty($model->proimg[3])) echo CHtml::link('删除图片','javascript:',array('class'=>'mem_btn filelink del ','onclick'=>"removeimg('4')"))?>
								<input type="hidden" id="proimage4" name="proimage[url][]"  value="<?php if(!empty($model->proimg[3])) echo $model->proimg[3]->zpg_url?>"/>
								<input type="hidden" id="proimgid4" name="proimage[id][]"  value="<?php if(!empty($model->proimg[3])) echo $model->proimg[3]->zta_id?>"/>
							</li>
							<li>
								<img id="img5" src="<?php if(!empty($model->proimg[4])){echo $model->proimg[4]->zpg_url;}else{echo "/images/pro_img.jpg";}?>" alt="" />
								<a class="mem_btn filelink" href="javascript:" onclick="uploadimg('5')">点击上传
									<input type="file" id="uploadimg5" multiple name="image"/>
								</a>
								<?php if(!empty($model->proimg[4])) echo CHtml::link('删除图片','javascript:',array('class'=>'mem_btn filelink del ','onclick'=>"removeimg('5')"))?>
								<input type="hidden" id="proimage5" name="proimage[url][]"  value="<?php if(!empty($model->proimg[4])) echo $model->proimg[4]->zpg_url?>"/>
								<input type="hidden" id="proimgid5" name="proimage[id][]"  value="<?php if(!empty($model->proimg[4])) echo $model->proimg[4]->zta_id?>"/>
							</li>
						</ul>
						<p class="note c_999">请上传1M以内的实拍产品图片，第一张图片为默认产品图片。</p>
					</div>
				</li>
				<!-- 产品图片 ebd -->
				<li class="c_f"><span class="tit"><em class="xing">*</em>宝贝描述：</span>
					<div class="cont f_l">
						<?php  $this->widget('ext.keditor.KEditor',array(
				            'model'=>$model,  //传入form model
				            'name'=>'zp_content', //设置name
				            'properties'=>array(
				                //设置接收文件上传的action
				                'uploadJson'=>'/Attachment/GetAjax',
				                //设置浏览服务器文件的action，这两个就是上面配置在/admin/default的
				             //   'fileManagerJson'=>'/Attachment/GetAjax',
				                'newlineTag'=>'br',
				                'allowFileManager'=>true,
				                //传值前加js:来标记这些是js代码
				                'afterCreate'=>"js:function() {
				                        K('#ChapterForm_all_len').val(this.count());
				                        K('#ChapterForm_word_len').val(this.count('text'));
				                    }",
				                'afterChange'=>"js:function() {
				                        K('#ChapterForm_all_len').val(this.count());
				                        K('#ChapterForm_word_len').val(this.count('text'));
				                    }",
				            ),
				            'textareaOptions'=>array(
				                'style'=>'width:635px;height:261px;',
				            )
				        )); ?>
						<p class="c_999">插入图片的规格：宽度小于750px</p>
					</div>
				</li>
			</ul>
			<div class="hd c_f"><h2 class="fs_14 f_l">2.宝贝物流信息</h2></div>
			<ul class="form_list">
				<li class="c_f"><span class="tit"><em class="xing">*</em>运费：</span>
				  <div class="cont f_l">
					  <ul class="sub_li">
					  	<?php echo CHtml::link('新增运费模板',array($this->pre_module_url.'express/freightcreate'),array('class'=>'c_06c f_r mr10','target'=>"_blank"))?>
					  	<?php echo $form->radioButtonList($model,'zp_exp_status',Product::model()->getExpStatus(),array('template'=>'<li>{input} {label}</li>','onclick'=>'templateshow()'));?>
						<li <?php if($model->zp_exp_status == 2) echo "class='select'"?> >
							<div class="template">
								<ul class="c_f">
									<?php echo $form->radioButtonList($model,'ze_id',Express::model()->getPressByActiveUser(),array('separator'=>'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;','onclick'=>'select()'))?>
								</ul>
							</div>
						</li>
					  </ul>
				  </div>
				</li>
			</ul>
	<?php if($model->isNewRecord){  //如果是修改产品，隐藏发布时间设置?>
			<div class="hd c_f"><h2 class="fs_14 f_l">3.发布时间设置</h2></div>
			<ul class="form_list">
				<li class="c_f"><span class="tit"></span>
				  <div class="cont f_l">
					  <ul class="sub_li">
						<li><input class="radio" type="radio" name="onlivetime" checked="checked" /><label>立即发布</label></li>
						<li><input class="radio" type="radio" name="onlivetime" /><label class="mr10">设置发布时间</label>
						<?php echo $form->textField($model,'zp_draft',array('onclick'=>"WdatePicker()",'class'=>'t_ipt ipt_bg'))?>
						</li>
					  </ul>
				  </div>
				</li>
			</ul>
	<?php  }?>
			<div class="hd c_f"><h2 class="fs_14 f_l">4.售后保障信息</h2></div>
			<ul class="form_list">
				<li class="c_f"><span class="tit">退换货承诺：</span>
				  <div class="cont f_l">
					  <span><?php echo $form->checkBox($model,'zp_guarantee')?>购买本店商品，若存在质量问题或与描述不符，本店将主动提供退换货服务并承担来回邮费!</span>
				  </div>
				</li>
				<li class="c_f"><span class="tit">售后说明：</span>
				  <div class="cont f_l">
				  	  <?php echo $form->dropDownList($model,'zbl_id',Block::model()->getSaleExpressByActiveUser(),array('class'=>'mr5'));?>
					  <?php echo CHtml::link('新增售后模板',array($this->pre_module_url.'/afterSales/admin#tab2'),array('class'=>'c_06c','target'=>"_blank"))?>
					  <p class="d_n"><a class="mem_bgx link_btn mr10" href="javascript:" title="">添加说明<b class="mem_bgx left"></b><b class="mem_bgx right"></b></a><span class="c_999">填写售后说明，让买家更清楚售后保障，减少纠纷</span></p>
				  </div>
				</li>
			</ul>
		</div>
		<div class="release_btn fs_14">
			<?php echo CHtml::submitButton($model->isNewRecord ? '发布产品' : '保 存',array('class'=>'mem_btn mem_btn05 mr5')); ?>
			<?php echo CHtml::link('预览','javascript:',array('class'=>'mem_btn mem_btn07','id'=>'editViewButton')) ?>
		</div>
</div>
<?php $this->endWidget(); ?>
<!--发布宝贝 end-->
<!-- 上传图片组件 -->
<script src="<?php echo Yii::app()->baseUrl;?>/js/upload_img.js"></script>
<script>
//点选规格
function selectSta(level,val,iscolor){
	$('.'+val+'').toggle(
		function(){
			//控制行的显示与隐藏
			if($(this).hasClass('d_n')){
				$(this).removeClass('d_n');
			}else{
				$(this).addClass('d_n');
			}
			//select 类名用于统计库存总数
			if($(this).hasClass('select')){
				$(this).removeClass('select');
			}else{
				$(this).addClass('select');
			}
			//如果选择两组规格，库存更改为不可编辑
			if($('#attSta .select .select .invent').length>0){
				$('#inventory').attr('readonly','readonly');
			}else{
				$('#inventory').attr('readonly',false);
			}
			//内嵌表格边框控制单边框
			$('#attSta .select .select').removeClass('b_t_no');
			for(var i=0;i<$('#attSta .select').length;i++){
				$('#attSta .select').eq(i).find('.select').eq(0).addClass('b_t_no');
			}
			
			//更新库存
			suminventory();
			//控制整个规格体系是否显示
			if($('#attSta .select .select .invent').length>0){
				$('#attSta').show();
			}else{
				$('#attSta').hide();
			}
			//控制规格颜色模块是否显示
			if($(this).parent().find('.select').length>0){
				if(iscolor!=null){
					$('#sta_color').show();
				}
			}else{
				if(iscolor!=null){
					$('#sta_color').hide();
				}
			}
		}
	);
}
//显示运费模板
function templateshow(){
	if($('#Product_zp_exp_status_1').attr('checked')){
		$('.template').parent().addClass("select");
	}else{
		$('.template').parent().removeClass("select");
	}
}
//计算产品总库存
function suminventory(){
	var a = 0;
	var c = $('#attSta .select .select .invent');
	for(i=0;i<c.length;i++){
		if(c.eq(i).val().length>0){
			var a = parseInt(c.eq(i).val())+parseInt(a);
		}
	}
	$('#inventory').val(a);
}
//输入规格库存自动计算总库存
$('.invent').blur(function(){suminventory()});

//表单验证
$('#product-form').bind('submit',function(){
	<?php if(count($cateSta)==2){?>
		//有两组规格的时候，选择规格必需选择两中规格，或者是不选择规格
		if($('#attSta .select').length>0){
			if($('#attSta .select .select').length<1){
				alert('规格必需选择两组或不选！');
				return false;
			}
		}
	<?php }else{?>
		if($('#attSta .select .select').length<1){
			return true;
		}
	<?php }?>
	
	var PminLimit=PmaxLimit=Pequal=false;
	for(var i=0;i<$('#attSta .select .select').length;i++){
		//规格价格
		var sta_price = parseFloat($('#attSta .select .select').eq(i).find('td').eq(1).find('input').val());
		//一口价
		var zp_price = parseFloat($('#product_zp_price').val());
		
		if($('#attSta .select .select').eq(i).find('td').eq(1).find('input').val().length<1){
			$('#attSta .select .select').eq(i).find('td').eq(1).find('input').addClass('error');
			alert('所选规格的产品价格不能为空！');
			return false;
		}
		if($('#attSta .select .select').eq(i).find('td').eq(2).find('input').val().length<1){
			$('#attSta .select .select').eq(i).find('td').eq(2).find('input').addClass('error');
			alert('所选规格的产品库存不能为空！');
			return false;
		}
		//是否存在一口价小于规格价格的
		if(zp_price<sta_price){
			PmaxLimit = true;
		}
		//是否存在一口价大于规格价格的
		if(zp_price>sta_price){
			PminLimit = true;
		}
		//是否存在一口价等于规格价格的
		if(zp_price==sta_price){
			Pequal = true;
		}
	}
	if(PminLimit&&PmaxLimit){
		return true;//一口价介于规格价格之间
	}else if(Pequal){
		return true;//一口价等于规格价格
	}else{
		alert('一口价必需小于所选规格对应的最大值，大于最小值！');
		return false;
	}
})

//预览
$('#editViewButton').bind('click',function(){
	$('#product-form').attr('action','<?php echo $this->pre_module_url?>/productCreate/editView');
	$('#product-form').attr('target','_blank');
	$('#product-form').submit();
	$('#product-form').attr('action','');
	$('#product-form').attr('target','');
});
</script>



<script>
jQuery(document).ready(function($) {
	$.formValidator.initConfig({theme:"126",formID:"product-form",
		onError:function(msg, obj){
					alert(msg);
					$(".element_box").hide();
					$(obj).closest(".element_box").show();
					$(".sub_nav ul li").removeClass("select");
					if($(obj).closest(".element_box").next().hasClass("element_box")){
						$(".sub_nav ul li").eq(0).addClass("select");
					}else{
						$(".sub_nav ul li").eq(1).addClass("select");
					}
					return false;
				},
		onsuccess:function(){ return true; }
	});
})
</script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/formvalidata/formValidator-4.1.1.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/formvalidata/formValidatorRegex.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/formvalidata/cmpValidate.js"></script>
<script language="javascript" type="text/javascript" src="<?php echo Yii::app()->baseUrl;?>/js/My97DatePicker/WdatePicker.js"></script>

